package com.hhkj.admin.student.service.base.impl;

import cn.hutool.core.util.ObjectUtil;
import com.hhkj.admin.student.mapper.StudentLoginLogMapper;
import com.hhkj.admin.student.model.dopo.StudentLoginLogDo;
import com.hhkj.admin.student.model.dopo.StudentLoginLogPo;
import com.hhkj.admin.student.model.dopo.StudentLoginTimesCountPo;
import com.hhkj.admin.student.service.base.StudentLoginLogService;
import com.ruoyi.common.base.biz.service.base.BaseServiceImpl;
import com.ruoyi.system.domain.StudentLoginLog;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 学员登录日志Service业务层处理
 *
 * @author ruoyi
 * @since 2023-05-22
 */
@Service
public class StudentLoginLogServiceImpl
        extends BaseServiceImpl<StudentLoginLog, StudentLoginLogDo, StudentLoginLogPo, StudentLoginLogMapper>
        implements StudentLoginLogService {


    @Override
    public List<StudentLoginTimesCountPo> listCountLoginByStudentIdListAndCourseIdList(List<Long> studentIdList) {
        return this.getBaseMapper().listCountLoginByStudentIdListAndCourseIdList(studentIdList);
    }

    @Override
    public Map<String, Set<Long>> courseIdSetGroupByIdCard(List<String> idCardList, Date timeStart, Date timeEnd) {
        List<StudentLoginLog> studentLoginLogList = this.getBaseMapper().courseIdSetGroupByIdCardAfterDate(idCardList, timeStart, timeEnd);
        Map<String, Set<Long>> map = new HashMap<>();
        studentLoginLogList.forEach(studentLoginLog -> {
            Set<Long> set = map.get(studentLoginLog.getIdCard());
            if (ObjectUtil.isEmpty(set)) {
                set = new HashSet<>();
                map.put(studentLoginLog.getIdCard(), set);
            }
            set.add(studentLoginLog.getCourseId());
        });
        return map;
    }
}
